﻿
// Condition: 4. Write a method that counts how many times given number appears in given array.
//               Write a test program to check if the method is working correctly.


using System;

class CountNumber
{
    // use loop to count given number appearence
    static int Count(int[] countArray, int num)
    {
        int count = 0;

        for (int i = 0; i < countArray.Length; i++)
        {
            if (countArray[i] == num)
            {
                count++;
            } 
        }
        return count;
    }

    static void Main(string[] args)
    {
        Console.Write("Enter number of elements in the array: ");
        int element = int.Parse(Console.ReadLine());
        int[] array = new int[element];
        // read array elements from console
        for (int i = 0; i < element; i++)
        {
            Console.Write("Element[{0}] = ",i);
            array[i] = int.Parse(Console.ReadLine());
        }

        Console.Write("Enter number you want to check: ");
        int check = int.Parse(Console.ReadLine());

        Console.WriteLine("The number {0} appears in the array - {1} times.",check, Count(array,check));
                
    }
}

